package com.example.allplan.RecyclerAdapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.example.allplan.JavaBean.BiaoQingLieBiao;
import com.example.allplan.R;
import com.example.allplan.StaticFangfa.BiaoQingZhuanHuan;

import java.util.ArrayList;
import java.util.zip.Inflater;

public class BiaoQingLieBiaoAdapter extends RecyclerView.Adapter<BiaoQingLieBiaoAdapter.ViewHolder> {
    ArrayList<BiaoQingLieBiao> mlist;
    LayoutInflater mli;
    onItemClickListener mlistener;
    public BiaoQingLieBiaoAdapter(ArrayList<BiaoQingLieBiao> mlist, Context mCon,onItemClickListener mlsn) {
        this.mlist = mlist;
        this.mlistener=mlsn;
        mli=LayoutInflater.from(mCon);
    }
    public interface onItemClickListener{
        void onClick(int pos);
    }
    @Override
    public BiaoQingLieBiaoAdapter.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
      View view= mli.inflate(R.layout.yi_ge_biao_qing_item,parent,false);
      return new ViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
        holder.mtext.setText(mlist.get(position).getBiao_qing_string());
        holder.mtext.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mlistener.onClick(holder.getAdapterPosition());
            }
        });
    }

    @Override
    public int getItemCount() {
        return mlist.size();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView mtext;

        public ViewHolder(View itemView) {
            super(itemView);
            mtext=itemView.findViewById(R.id.yi_ge_biao_qing_item);
        }
    }
}
